<template>
  <div style="widows: 70%; margin-left: 5%">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="工序编号" >
        <el-col>
          <el-input disabled></el-input>
        </el-col>
        <el-col style="margin-left: 10px">
          <el-switch v-model="ruleForm.aaa"></el-switch>系统编号
        </el-col>
      </el-form-item>
      <el-form-item label="工序名称" prop="processname">
        <el-col>
          <el-input v-model="ruleForm.processname"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="状态" prop="processstate">
        <el-radio v-model="ruleForm.processstate" label="启用">启用</el-radio>
        <el-radio v-model="ruleForm.processstate" label="禁用">禁用</el-radio>
      </el-form-item>
      <el-form-item label="工序说明">
        <el-input type="textarea" v-model="ruleForm.processexplain"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="ruleForm.processremark"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >确认</el-button
        >
        <el-button type="primary" @click="tiao()">关闭</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
  <script>
import { processAdd } from "../../api/process";
export default {
  data() {
    return {
      ruleForm: {
        processname: "",
        processstate: "",
        processexplain: "",
        processremark: "",
      },
      aaa: false,
      rules: {
        processname: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
        processstate: [
          { required: true, message: "请输入活动名称", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //alert("submit!");
          processAdd(this.ruleForm).then((ros) => {
            if (ros.result > 0) {
              alert("添加成功");
            } else {
              alert("添加失败");
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    tiao()
    {
      this.$router.push('ProcessShow')
    }
  },
};
</script>